// https://vitepress.dev/guide/custom-theme
import { h } from "vue";
import type { Route, Theme } from "vitepress";
import DefaultTheme from "vitepress/theme";
import "./style.css";
import PostList from "./PostList.vue";
import { RoutersSymbol } from "./constant";
import { findSourceDir } from "./utils";

export default {
  extends: DefaultTheme,
  Layout: () => {
    return h(DefaultTheme.Layout, null, {
      // https://vitepress.dev/guide/extending-default-theme#layout-slots
      "home-features-after": () =>
        h(PostList, {
          type: "home-features-after",
          // style: "display:none;",
        }),
    });
  },
  async enhanceApp({ app, router, siteData }) {
    const routers = findSourceDir(siteData.value.base);
    app.provide(RoutersSymbol, routers);
    if (!import.meta.env.SSR) {
      const plugin = await import("vue-waterfall-plugin-next");
      app.component("Waterfall", plugin.Waterfall);
      app.component("LazyImg", plugin.LazyImg);
    }
  },
} satisfies Theme;
